package cn.ai.boot.config;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author jie.zhao@dms365.com
 * @Date 2025/7/2 11:56
 */
public class Test333333 {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(50);

        AsyncServiceUtils service = new AsyncServiceUtils();
        Map<String, Map<String, Object>> map = new HashMap<>();
        for (int i = 0; i < 100; i++) {
            Map<String, Object> innerMap = new HashMap<>();
            innerMap.put("key1", "value" + i);
            innerMap.put("key2", i);

            map.put("outerKey" + i, innerMap);
        }
        try {

//            service.executeConcurrentTasks(executorService, map, 10,
//                    key -> {
//                        System.out.println("Processing: " + key);
//                        try {
//                            Thread.sleep(2000L);
//                        } catch (InterruptedException e) {
//                            throw new RuntimeException(e);
//                        }
//                    }, "myThreadPool");


            System.out.println("map处理完成============");

            List<String> folderAuths = new ArrayList<>();
            for (int i = 0; i < 200; i++) {
                folderAuths.add("" + i);
            }

            List<List<String>> partition = Lists.partition(folderAuths, 20);

            service.executeConcurrentTasks(executorService, partition, 5,
                    list -> {
                        System.out.println("Processing: start" + list);
                        try {
                            if (list.contains("58")) {
                            }
                            Thread.sleep(2000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        System.out.println("Processing:end " + list);

                    }, "myThreadPool");


        } catch (Exception e) {
            System.out.println("发送了异常");
        } finally {
            executorService.shutdown();
        }
    }
}
